home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -websites- / wirenet / files / thor26_arexx.lha / Rexx / OptConf.thor < prev    next >
Text File  |  1999-01-17  |  14KB  |  476 lines

  1. /*
  2.  * $VER: OptConf V1.20 (14.12.97)
  3.  * Shaun Downend <shaund@amiganut.demon.co.uk>
  4.  *         Optimise a conference in a BBS.
  5.  *
  6.  * Modified by Petter Nilsen after Bernd Gollesch's detective
  7.  * work.
  8.  */
  9.  
  10. /* Optional configuration items */
  11.  
  12. repackxpk = 1   /* during optimisation XPK packed conferences are unpacked.
  13.                  * set this to 1 to repack, or 0 to not repack.
  14.                  */
  15. xpk = 0
  16.  
  17. /* End configuration */
  18.  
  19. scriptver = subword(sourceline(1), 4,1)
  20. scriptinfo = 'OptConf.thor 'scriptver' © Shaun Downend.'
  21.  
  22. /*!~ "Bit numbers for message flags" */
  23.  
  24. MDB_READ          =  0   /* Message is read. */
  25. MDB_REPLIED       =  1   /* Message is replied. */
  26. MDB_PRIVATE       =  2   /* Message is private. */
  27. MDB_TO_USER       =  3   /* Message is to the user. */
  28. MDB_FROM_USER     =  4   /* Message is from the user. */
  29. MDB_DELETED       =  5   /* Message is deleted. */
  30. MDB_UNRECOVERABLE =  6   /* Message is can not be undeleted. */
  31. MDB_KEEP          =  7   /* Keep message. Message will not be deleted during conference packing. */
  32. MDB_TO_ALL        =  8   /* Message is to all. (has no reciever) */
  33. MDB_XPK_TEXT      =  9   /* Message text is Xpk'ed. (Private flag) */
  34. MDB_MARKED        = 10   /* Message is marked.  */
  35. MDB_URGENT        = 11   /* Message is urgent.  */
  36. MDB_IMPORTANT     = 12   /* Message is important. */
  37. MDB_SUPERMARKED   = 13   /* Message will not be unmarked as long as this flag is set. */
  38.  
  39. CDF_NOT_ON_BBS   = '00008000'x  /* This conference is not on the bbs. */
  40. CDB_NO_XPK_METHOD       = 13    /* Don't use any xpk method. */
  41.  
  42. BDB_NO_XPK_METHOD      = 4   /* Don't use any xpk method. */
  43. GCB_NO_XPK_METHOD      = 3   /* Don't use any xpk method. */
  44.  
  45. /*~!*/
  46.  
  47. options results
  48. options failat 31
  49.  
  50. signal on halt
  51. signal on break_c
  52. signal on failure
  53.  
  54. /*!~ "Open Thor and BBSREAD ARexx ports" */
  55.  
  56. p=' '||address()||' '||show('P',,)
  57. if pos(' THOR.',p)>0 then
  58. thorport=word(substr(p,pos(' THOR.',p)+1),1)
  59. else
  60. do
  61.     say ('Thor has to be running to use this script!')
  62.     exit(0)
  63. end
  64.  
  65. if ~show('p', 'BBSREAD') then
  66. do
  67.     address command
  68.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  69.     'WaitForPort BBSREAD'
  70.     if rc ~= 0 then call errmsg('Couldn''t open BBSRead''s ARexx port.')
  71. end
  72.  
  73. address(thorport)
  74. 'VERSION STEM 'version
  75.  
  76. fullver = subword(version.THOR, 1, 1)
  77. version.thorver = substr(fullver, 1, index(fullver, '.') - 1)
  78. version.thorrev = compress(substr(fullver, index(fullver, '.') + 1), 'ß')
  79.  
  80. thorversion = version.thorver || '.' || version.thorrev
  81.  
  82. if thorversion < 2.5 then call errmsg('You need at least Thor 2.5 to run this script!')
  83.  
  84. /*~!*/
  85.  
  86. /*!~ "Get list of conference(s) to optimise" */
  87.  
  88. address(thorport)
  89.  
  90. 'currentsystem' CURRENT
  91. if(rc = 1) then call errmsg('CURRENTSYSTEM failed: No current system')
  92. if(rc = 30) then call errmsg('CURRENTSYSTEM failed: 'THOR.LASTERROR)
  93.  
  94. address BBSREAD 'getconflist bbsname "'CURRENT.BBSNAME'" stem' CONFLIST
  95. if(rc = 5) then call errmsg('GETCONFLIST failed: BBS not found')
  96. if(rc ~= 0) then call errmsg('GETCONFLIST failed: 'BBSREAD.LASTERROR)
  97.  
  98. 'requestlist instem' CONFLIST 'outstem' SELECTED 'multiselect dragselect title "Select conference(s) to optimise:"'
  99. if(rc = 5) then exit
  100. if(rc ~= 0) then call errmsg('REQUESTLIST failed: 'THOR.LASTERROR)
  101.  
  102. 'lockgui'
  103.  
  104. address(BBSREAD)
  105.  
  106. drop CONFDATA.
  107. drop BBSDATA.
  108. drop GLOBDATA.
  109.  
  110. /* Get System and Global XPK settings */
  111.  
  112. 'getbbsdata bbsname "'CURRENT.BBSNAME'" stem' BBSDATA
  113. if(rc =  5) then call errmsg('GETBBSDATA failed: BBS name not found')
  114. if(rc = 30) then call errmsg('GETBBSDATA failed: 'BBSREAD.LASTERROR)
  115.  
  116. 'getglobaldata stem' GLOBDATA
  117. if(rc = 30) then call errmsg('GETGLOBALDATA failed: 'BBSREAD.LASTERROR)
  118.  
  119. ptotal = 0
  120.  
  121. longest = 0
  122.  
  123. /* Work out information for progress indicator */
  124.  
  125. do i = 1 to SELECTED.COUNT
  126.  
  127.     'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'SELECTED.i'" stem' CONFDATA
  128.     if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  129.     if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  130.  
  131.     /* find the longest conference name to fix width of progress indicator */
  132.     if length(SELECTED.i) > longest then longest = length(SELECTED.i)
  133.  
  134.     /* find out if the conference is xpk packed, if so then this requires another step */
  135.     if CONFDATA.XPKMETHOD ~= '' then xpk = 10000
  136.     else
  137.     do
  138.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpk = 0
  139.         else
  140.         do
  141.             if BBSDATA.XPKMETHOD ~= '' then xpk = 10000
  142.             else
  143.             do
  144.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpk = 0
  145.                 else
  146.                 do
  147.                     if GLOBDATA.XPKMETHOD ~= ''  then xpk = 10000
  148.                     else
  149.                     do
  150.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpk = 0
  151.                     end
  152.                 end
  153.             end
  154.         end
  155.     end
  156.  
  157.     /* total of progress indicator is xpk + create conf (10000) + copy msgs (10000)
  158.      * + pack conf (10000) + delete msgs (10000) + delete conf (10000).
  159.      * 10000 is used (a large value) to reduce inaccuracies on division later on.
  160.      */
  161.     ptotal = ptotal + xpk + 60000
  162. end
  163.  
  164. longest = length('Copying messages in ') + longest + length('to ') + longest + length('.temp')
  165.  
  166. /* open and fix progress indicator width */
  167. call oprog(scriptinfo,ptotal,center('...Starting OptConf.thor...Initialising script...',longest,' '))
  168.  
  169. pcurrent = 0
  170.  
  171. 'bufmode copyback'      /* Turn on copyback mode  */
  172.  
  173. /*~!*/
  174.  
  175. /*!~ "Main loop" */
  176. do n = 1 to SELECTED.COUNT
  177.  
  178.     conference = SELECTED.n
  179.  
  180.     tempconf  = conference'.temp'
  181.  
  182.     call getmsginfo(conference) /* get msg numbers for selected conference */
  183.  
  184.     xpkpack = 0
  185.     /* is conference xpk packed? */
  186.  
  187.     if CONFDATA.XPKMETHOD ~= '' then xpkpack = 1
  188.     else
  189.     do
  190.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpkpack = 0
  191.         else
  192.         do
  193.             if BBSDATA.XPKMETHOD ~= '' then xpkpack = 1
  194.             else
  195.             do
  196.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpkpack = 0
  197.                 else
  198.                 do
  199.                     if GLOBDATA.XPKMETHOD ~= ''  then xpkpack = 1
  200.                     else
  201.                     do
  202.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpkpack = 0
  203.                     end
  204.                 end
  205.             end
  206.         end
  207.     end
  208.  
  209.     call uprog(window,pcurrent,'Creating temporary conference 'tempconf'...')
  210.  
  211.     pcurrent = pcurrent + 10000
  212.  
  213.     /* create temporary conference */
  214.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" set' c2x(CDF_NOT_ON_BBS)
  215.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  216.  
  217.     call copyconf(conference,tempconf) /* copy msgs from orig conf to temp conf */
  218.  
  219.     /*!~ "Delete messages in original conference" */
  220.     call uprog(window,pcurrent,'Deleting messages in 'conference)
  221.  
  222.     pstart = pcurrent
  223.  
  224.     if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  225.     do
  226.         pinc = 10000 %  (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  227.  
  228.         do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  229.  
  230.             drop OLDMSGDATA.
  231.  
  232.             if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  233.  
  234.             pcurrent = pcurrent + pinc
  235.  
  236.             'readbrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'datastem' OLDMSGDATA
  237.             if(rc ~= 0) then call bbsreaderr
  238.  
  239.             if ~bittst(OLDMSGDATA.FLAGS,MDB_DELETED) then /* is message already deleted? */
  240.             do
  241.                 'updatebrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'setdeleted'
  242.                 if(rc ~= 0) then call bbsreaderr
  243.             end
  244.         end
  245.         pcurrent = pstart + 10000 /* adjust to fix any inaccuracies in previous division :-) */
  246.     end
  247.     else /* conference is empty so skip */
  248.     do
  249.         pinc = pstart + 10000
  250.         call uprog(window,pcurrent)
  251.     end
  252.     /*~!*/
  253.  
  254.     /*!~ "Pack original conference" */
  255.  
  256.     call uprog(window,pcurrent,'Clearing 'conference'...')
  257.  
  258.     pcurrent = pcurrent + 10000
  259.  
  260.     'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  261.     if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  262.     /*~!*/
  263.  
  264.     call getmsginfo(tempconf) /* get msg numbers for temp conf */
  265.  
  266.     call copyconf(tempconf,conference) /* copy msgs from temp conf to orig conf */
  267.  
  268.     /*!~ "Delete temporary conference" */
  269.     call uprog(window,pcurrent,'Deleting 'tempconf'...')
  270.  
  271.     pcurrent = pcurrent + 10000
  272.  
  273.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  274.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  275.  
  276.     /*~!*/
  277.  
  278.     /*!~ "Repack XPK packed conference" */
  279.     if repackxpk = 1 then
  280.     do
  281.         if xpkpack = 1 then
  282.         do  /* If conference was xpk-packed then pack it */
  283.             call uprog(window,pcurrent,'XPK Packing 'conference'...')
  284.  
  285.             pcurrent = pcurrent + 10000
  286.  
  287.             address(BBSREAD)
  288.             'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  289.             if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  290.  
  291.         end
  292.     end
  293.     /*~!*/
  294.  
  295. end
  296.  
  297. call uprog(window,pcurrent,'Complete.')
  298. do i = 1 to 600
  299. end
  300.  
  301. pcurrent = pcurrent + 10000
  302.  
  303. /*!~ "Notify completion, update conf window, cleanup" */
  304. address(thorport)
  305. 'updateconfwindow'
  306. 'unlockgui'
  307. address(bbsread)
  308. 'bufmode endcopyback'
  309. call cprog(window)
  310. address(thorport)
  311. 'requestnotify "OptConf.thor complete!"' '" _OK "'
  312. if(rc = 30) then say THOR.LASTERROR
  313.  
  314. exit
  315. /*~!*/
  316.  
  317. /*~!*/
  318.  
  319. /*!~ "Copy all messages from one conference to another conference " */
  320. copyconf:
  321.  
  322. parse arg fromconf,toconf
  323.  
  324. call uprog(window,pcurrent,'Copying messages in 'fromconf 'to 'toconf)
  325.  
  326. pstart = pcurrent
  327.  
  328. if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  329. do
  330.     pinc = 10000 % (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  331.  
  332.     do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  333.  
  334.         drop MSGTAGS.
  335.         drop MSGDATA.
  336.  
  337.         if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  338.  
  339.         pcurrent = pcurrent + pinc
  340.  
  341.         'readbrmessage "'CURRENT.BBSNAME'"' '"'fromconf'"' i 'headstem' MSGTAGS 'textstem' MSGTAGS 'datastem' MSGDATA
  342.         if(rc ~= 0) then call bbsreaderr
  343.  
  344.         if ~bittst(MSGDATA.FLAGS,MDB_DELETED) | ~bittst(MSGDATA.FLAGS,MDB_UNRECOVERABLE) then
  345.         do
  346.             exargs = ''
  347.             if ~bittst(MSGDATA.FLAGS,MDB_MARKED)   then exargs = exargs || ' DONTMARKMESSAGE'
  348.             if bittst(MSGDATA.FLAGS,MDB_PRIVATE)   then exargs = exargs || ' PRIVATE'
  349.             if bittst(MSGDATA.FLAGS,MDB_READ)      then exargs = exargs || ' READ'
  350.             if bittst(MSGDATA.FLAGS,MDB_URGENT)    then exargs = exargs || ' URGENT'
  351.             if bittst(MSGDATA.FLAGS,MDB_IMPORTANT) then exargs = exargs || ' IMPORTANT'
  352.  
  353.             'writebrmessage "'CURRENT.BBSNAME'"' '"'toconf'" stem' MSGTAGS exargs
  354.             if(rc ~= 0) then call bbsreaderr
  355.  
  356.             msgnr = result
  357.  
  358.             exargs = ''
  359.  
  360.             if bittst(MSGDATA.FLAGS,MDB_KEEP)    then exargs = exargs || ' SETKEEP'
  361.             if bittst(MSGDATA.FLAGS,MDB_SUPERMARKED) then exargs = exargs || ' SETSUPERUNREAD'
  362.             if bittst(MSGDATA.FLAGS,MDB_REPLIED) then exargs = exargs || ' SETREPLIED'
  363.  
  364.             if MSGDATA.HAZELEVEL ~= 0 then exargs = exargs || ' HAZELEVEL ' || MSGDATA.HAZELEVEL
  365.  
  366.             if exargs ~= '' then 'updatebrmessage "'CURRENT.BBSNAME'"' '"'toconf'"' msgnr exargs
  367.             if(rc ~= 0) then call bbsreaderr
  368.  
  369.         end
  370.         /*
  371.         else say 'Message deleted or unrecoverable'
  372.         */
  373.     end
  374.     pcurrent = pstart + 10000 /* adjust for any inaccuracies in previous division :-) */
  375. end
  376. else /* conference is empty so skip it */
  377. do
  378.     pinc = pstart + 10000
  379.     call uprog(window,pcurrent)
  380. end
  381.  
  382. return
  383. /*~!*/
  384.  
  385. /*!~ "Get message numbers for a conference" */
  386. getmsginfo:
  387. parse arg conf
  388.  
  389. drop CONFDATA.
  390.  
  391. 'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'conf'" stem' CONFDATA
  392. if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  393. if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  394.  
  395. return
  396. /*~!*/
  397.  
  398. /*!~ "Progress indication" */
  399.  
  400. /*!~ "Open progress indicator" */
  401. oprog:
  402. parse arg ptitle,ptotal,ptxt
  403. address(thorport)
  404. 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"'
  405. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  406. else window = result
  407. return
  408. /*~!*/
  409.  
  410. /*!~ "Update progress indicator" */
  411. uprog:
  412. parse arg pwindow,pcurrent,ptxt
  413. /*
  414. say 'current 'pcurrent
  415. */
  416. if ptxt = '' then ptxt = ''
  417. else ptxt = 'pt ' || '"'ptxt'"'
  418. address(thorport)
  419. 'updateprogress req' pwindow 'current' pcurrent ptxt
  420. if(rc~=0) then signal cleanup
  421. return(0)
  422. /*~!*/
  423.  
  424. /*!~ "Close Progress indicator" */
  425. cprog:
  426. parse arg pwindow
  427. address(thorport)
  428. 'closeprogress req' pwindow
  429. return
  430. /*~!*/
  431.  
  432. /*~!*/
  433.  
  434. /*!~ "Error handling" */
  435. break_c:
  436.  
  437. call errmsg('User break!')
  438.  
  439. error:
  440. halt:
  441. failure:
  442.  
  443. if rc ~= 0 then call errmsg('+++ Line 'sigl' returned 'rc': 'errortext(rc))
  444.  
  445. cleanup:
  446.  
  447. address(bbsread)
  448. 'bufmode endcopyback'
  449. if window ~= 'WINDOW' then call cprog(window)
  450. address(thorport)
  451. 'unlockgui'
  452. exit(0)
  453.  
  454. errmsg:
  455. parse arg msgtxt
  456. address(thorport)
  457. 'requestnotify "'msgtxt'"' '" _OK "'
  458. if(rc = 30) then say THOR.LASTERROR
  459. signal cleanup
  460. return
  461.  
  462. bbsreaderr:
  463. address(bbsread)
  464. 'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  465. if(rc ~= 0) then
  466. do
  467.     address(thorport)
  468.     'requestnotify "CONFIGCONF failed: 'BBSREAD.LASTERROR'\nFailed to delete temporary conference."' '" _OK "'
  469. end
  470. address(thorport)
  471. 'requestnotify "BBSRead Error: 'BBSREAD.LASTERROR'\nThere appears to be a problem with the database.\nPlease repair the database before running this script.\nSystem    : 'CURRENT.BBSNAME'\nConference: 'fromconf'\nMessage no: 'i'."' '" _OK "'
  472. signal cleanup
  473. return
  474. /*~!*/
  475.  
  476.